package com.zhangy.controller;
import com.zhangy.model.Shangpu;
import com.zhangy.service.ShangpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
@CrossOrigin
@Transactional
@Controller
@ResponseBody
public class ShangpuController {
    @Autowired
    private ShangpuService shangpuService ;
    @RequestMapping("addShangpu")
    public void addShangpu(Shangpu shangpu){
        shangpuService.addShangpu(shangpu);
    }
    @RequestMapping("delShangpu")
    public void delShangpu(String ids){
        String[] split = ids.split(",");
        List<Integer> arrList=new ArrayList<Integer>();
        for (String idd: split) {
            arrList.add(Integer.parseInt(idd));
        }
        shangpuService.delShangpu(arrList);
    }
    @RequestMapping("selShangpuById")
    public Shangpu selShangpuById(int spid){
        return shangpuService.selShangpuById(spid);
    }
    @RequestMapping("updateShangpu")
    public void updateShangpu(Shangpu shangpu){
        shangpuService.updateShangpu(shangpu);
    }
    @RequestMapping("selectShangpuList")
    public List<Shangpu> selectShangpuList(){
        List<Shangpu> shangpus = shangpuService.selectShangpuList();
        return shangpus;
    }
}